<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <meta charset="UTF-8">
    <title>Pyscript Demo</title>
    <link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" />
    <script defer src="https://pyscript.net/alpha/pyscript.js"></script>
    <!-- <script type="text/javascript" src="https://cdn.bokeh.org/bokeh/release/bokeh-2.4.2.js"></script>
    <script type="text/javascript" src="https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.4.2.min.js"></script>
    <script type="text/javascript" src="https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.4.2.min.js"></script>
    <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/@holoviz/panel@0.13.1/dist/panel.min.js"></script>
 -->
    <py-env>
        - pandas
        - scikit-learn
        - matplotlib
    </py-env>
</head>
<body>
<input  style="display:none;"  type="text" id="area" th:value="${teaShopOrder}"/>

<div id="plot" ></div>
</body>
</html>
<py-script output = "plot">
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
from sklearn.linear_model import LinearRegression
import datetime
import random

data = str(document.getElementById("area").value);
prices_dates = []
for item in data.split(","):
    price = int(item.split("price=")[1].split(" ")[0])
    date_str = item.split("date=")[1].strip("]").strip()
    date = datetime.datetime.strptime(date_str, "%Y-%m-%d")
    prices_dates.append([price, date])

x = [item[1].date() for item in prices_dates]
y = [item[0] for item in prices_dates]
result = {}
for i in range(len(x)):
    if x[i] not in result:
        result[x[i]] = y[i]
    else:
        result[x[i]] += y[i]
x = list(result.keys())
y = list(result.values())
z = {'Date':x, 'Money':y}
df = pd.DataFrame(z)
plt.figure(figsize=(12, 5), dpi = 1000)
plt.bar(df['Date'], df['Money'], color='darkturquoise')
plt.title('Daily Sales Bar Chart')
plt.xlabel('Date')
plt.ylabel('Sales')
plt.axhline(y = np.mean(y),color = "red", label='Average Daily Sales')
plt.legend()
plt.grid(alpha=0.8, linestyle = '--')
plt
</py-script>
